<template>
  <div class="seal-editor-wrapper page-miH page-bgBack">
    <PageHeader @back="back" subTitle="返回"> 企业认证 </PageHeader>
    <div class="seal-editor-content">
      <div class="seal-editor-content-block">
        <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
          <a-form-item label="企业全称">
            <a-input v-model="companyName" :default-value="currentCompanyName" />
          </a-form-item>
          <a-form-item label="组织机构代码/社会统一信用代码">
            <div class="seal-editor-type-wrapper" style="margin-bottom: 10px">
              <div :class="{ active: regType === 'NORMAL' }" class="seal-editor-btnType" @click="setType('NORMAL')">组织机构代码</div>
              <div :class="{ active: regType === 'MERGE' }" class="seal-editor-btnType" @click="setType('MERGE')">社会统一信用代码</div>
            </div>
            <a-input v-model="organCode" />
            <div v-if="regType === 'NORMAL'" class="seal-editor-content-block-tip">请输入9位组织机构代码</div>
            <div v-else class="seal-editor-content-block-tip">请输入社会统一信用代码</div>
          </a-form-item>
          <a-form-item label="法人姓名">
            <a-input v-model="legalName" />
            <div class="seal-editor-content-block-tip">按照营业执照上填写的法人姓名</div>
          </a-form-item>
          <a-form-item label="法人身份证">
            <a-input v-model="agentIdNo" />
          </a-form-item>
        </a-form>
      </div>
    </div>
    <div class="seal-editor-footer">
      <a-button type="primary" @click="submit">提交</a-button>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
import { getCompanies } from "@/api/company/index";
import { sealVerifyReq } from "@/api/company/contract";
import { isContainByString } from "@/utils/index";
export default {
  data() {
    return {
      isContainByString,
      companies: [],
      defaultValue: null,
      companyName: "",
      regType: "NORMAL",
      organCode: "",
      legalName: "",
      agentIdNo: ""
    };
  },
  computed: {
    ...mapState(["hr"]),
    companyId: function () {
      return this.hr.companyId;
    },
    currentCompanyName: function () {
      return this.hr.companyName;
    }
  },

  created() {
    this.loadCompanies();
  },

  methods: {
    setType(type) {
      this.regType = type;
    },
    back() {
      this.$router.back();
    },
    submit() {
      sealVerifyReq({
        companyId: this.isContainByString("contractAdmin") ? "0" : this.companyId,
        companyName: this.companyName,
        regType: this.regType,
        organCode: this.organCode,
        legalName: this.legalName,
        agentIdNo: this.agentIdNo,
        sealId: this.$route.params.id
      })
        .then((res) => {
          this.$message.success("认证成功");
          this.$router.push(`/${this.isContainByString("contractAdmin") ? "contractAdmin" : "contract"}/stamp`);
        })
        .catch((err) => {
          console.log("debug log --> ", err);
          this.$message.success("认证失败");
        });
    },
    loadCompanies() {
      getCompanies()
        .then((res) => {
          this.companies = res.data.entities;
        })
        .catch((err) => {
          console.log("debug log --> ", err);
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.seal-editor-wrapper {
  .left2 {
    z-index: 3;
    left: 50px;
    position: absolute;
    color: #595959;
    font-size: 16px;
    margin-top: -1px;
  }
}
</style>
